﻿//===============================================================================
// Microsoft Innovation Centre - Western Europe
// Copyright (c) 2008 Microsoft Corporation. All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Web.Profile;

namespace Microsoft.WVB.Server
{
    public static class EntityConvert
    {
        public static void PopulateProfileInfo(WVBProfile profile, ref ProfileBase profileBase)
        {
            if ((profileBase != null) && (profile != null))
            {
                profileBase.GetProfileGroup("Personal").SetPropertyValue("Firstname", profile.FirstName);
                profileBase.GetProfileGroup("Personal").SetPropertyValue("Lastname", profile.LastName);
                profileBase.GetProfileGroup("Personal").SetPropertyValue("Birthdate", profile.BirthDate);
                profileBase.GetProfileGroup("Personal").SetPropertyValue("Gender", profile.Gender.ToString());
                profileBase.GetProfileGroup("Personal").SetPropertyValue("PPID", profile.Username);
                profileBase.GetProfileGroup("Personal").SetPropertyValue("Level", profile.Level.ToString());

                profileBase.GetProfileGroup("Others").SetPropertyValue("Country", profile.Country);
                profileBase.GetProfileGroup("Others").SetPropertyValue("Zipcode", profile.ZipCode);
                profileBase.GetProfileGroup("Others").SetPropertyValue("JobTitle", profile.JobTitle);
                profileBase.GetProfileGroup("Others").SetPropertyValue("Industry", profile.Industry);
                profileBase.GetProfileGroup("Others").SetPropertyValue("CompagnySize", profile.CompanySize);
                profileBase.GetProfileGroup("Others").SetPropertyValue("Income", profile.Income);
                profileBase.GetProfileGroup("Others").SetPropertyValue("Interests", profile.Interests);
            }
        }

        public static WVBProfile ConvertToWVBProfile(ProfileBase profileBase)
        {
            WVBProfile profile = null;

            if (profileBase != null)
            {
                profile = new WVBProfile();
                profile.Username = profileBase.UserName;
                profile.FirstName = (string) profileBase.GetProfileGroup("Personal").GetPropertyValue("Firstname");
                profile.LastName = (string) profileBase.GetProfileGroup("Personal").GetPropertyValue("Lastname");
                profile.BirthDate = (DateTime) profileBase.GetProfileGroup("Personal").GetPropertyValue("Birthdate") ;
                profile.Gender = (Gender) Enum.Parse(typeof(Gender), (string) profileBase.GetProfileGroup("Personal").GetPropertyValue("Gender"));
                profile.Level = (ProfileLevel) Enum.Parse(typeof(ProfileLevel), (string) profileBase.GetProfileGroup("Personal").GetPropertyValue("Level"));

                profile.Country = (string) profileBase.GetProfileGroup("Others").GetPropertyValue("Country");
                profile.ZipCode = (int) profileBase.GetProfileGroup("Others").GetPropertyValue("Zipcode");
                profile.JobTitle = (string) profileBase.GetProfileGroup("Others").GetPropertyValue("JobTitle");
                profile.Industry = (string) profileBase.GetProfileGroup("Others").GetPropertyValue("Industry");
                profile.CompanySize = (int) profileBase.GetProfileGroup("Others").GetPropertyValue("CompagnySize");
                profile.Income = (double) profileBase.GetProfileGroup("Others").GetPropertyValue("Income");
                profile.Interests = (string)profileBase.GetProfileGroup("Others").GetPropertyValue("Interests");
            }
            return profile;
        }
    }
}